<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */
namespace App\Admin\Request;

use App\Overwrites\MineFormRequest;

/**
 * 车辆分类配置验证数据类
 */
class CarCategoryRequest extends MineFormRequest
{
    /**
     * 公共规则
     */
    public function commonRules(): array
    {
        return [];
    }

    /**
     * 新增数据验证规则
     * return array
     */
    public function saveRules(): array
    {
        return [
            //名称 验证
            'name' => 'required|string|max:10|unique:car_categories',
            //ICON 验证
            'icon' => 'nullable|string|max:255|url',
            //权重 验证
            'weight' => 'required|integer|between:0,65535',
        ];
    }

    /**
     * 更新数据验证规则
     * return array
     */
    public function updateRules(): array
    {
        $rules = $this->saveRules();
        $rules['name'] .= ',name,' . $this->route('id');
        return $rules;
    }

    
    /**
     * 字段映射名称
     * return array
     */
    public function attributes(): array
    {
        return [
            'id' => '',
            'name' => '名称',
            'icon' => 'ICON',
            'weight' => '权重',
        ];
    }

    protected function prepareForValidation()
    {
        $this->merge([
            'icon' => (string)$this->input('icon'),
        ]);
    }
}